#ifndef GAME_H
#define	GAME_H

#include <allegro5/allegro.h>
#include <allegro5/allegro_font.h>
#include <allegro5/allegro_ttf.h>
#include <allegro5/allegro_native_dialog.h>
#include <allegro5/allegro_primitives.h>
#include "data_struct_game.h"

/**
 * @param field used to store the position of every block locked.
 * */
extern block_type field[height_matrix][width_matrix];  

/**
 * This function manages the game loop
 * 
 * When this function is closed you are redirected to:
 * Menu() if you aren't in the leaderboard
 * SaveScore() if you enter in the leaderboard
 * */
int Game();

/**
 * This function sets the value N in every cell of the matrix.
 * */
void ResetField();

/**
 * This function draws the background line and the game info.
 * */
void DrawDisplay();

/**
 * This function initializes the needed variable to start the game.  
 * */
void InitGame();

/**
 * This function initializes the new block that appears on the field.
 * The function return the block.
 *
 * @param done is used to check if the game is over.
 * */
pivot InitBlock(bool &done);

/**
 * The function NewBlock randomizes the next block that appears on the field.
 * The function returns the value of the new block.
 * */
block_type NewBlock();

/**
 * The function GameOver checks if the new block collides with the blocks already
 * present on the field.
 * The function returns true if the new block can move, false if collide.
 * */
bool GameOver();

/**
 * This function draws the single block based on the type of the block.
 * */
void DrawBlock();

/**
 * This function checks if the block can move down, based on the type of
 * the block, or is stuck with other block, in that case the block is stopped.
 * */
bool MoveDown();

/**
 * This function checks if the block can rotate. If not the rotation is
 * not allowed.
 * */
void Rotation();

/**
 * This function checks if the block can move down, based on the type of
 * the block and the actual rotation.
 * */
bool CanRotate();

/**
 * This function saves the position of the block on the matrix.
 * */
void Block();

/**
 * This function checks if the row is completed and calculates the number 
 * of row deleted, updates the total score and checks the level.
 * */
void DeleteRow();

/**
 * This function updates the value in the matrix.
 * @param row_deleted contains the row completed that must be cleared.
 * */
void ShiftRowDown(int row_deleted);

/**
 * This function draws the field based on the value of the matrix.
 * */
void DrawField();

/**
 * This function draws, based on the type of the block, the block
 * on the top right corner of the window.
 * */
void DrawNextBlock();

#endif	/* GAME_H */

